local hunqian = fk.CreateSkill {
  name = "th_hunqian",
  max_turn_use_time = 1,
}

hunqian:addEffect("viewas", {
  pattern = ".|.|.|.|.|normal_trick|.",
  expand_pile = "$th_alice_renxing",
  anim_type = "control",
  mute_card = false,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("t")
    local names = player:getViewAsCardNames(hunqian.name, all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  prompt = function(self, player, selected_cards, selected)
    local prompt = Fk:translate("#th_hunqian"):gsub("%%arg", Fk:translate(self.interaction.data))
    if #player:getPile("$th_alice_renxing") == 1 then
      prompt = prompt .. Fk:translate("#th_hunqian-draw")
    end
    return prompt
  end,
  filter_pattern = {
    min_num = 1,
    max_num = 1,
    pattern = ".|.|.|$th_alice_renxing"
  },
  view_as = function(self, player, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = hunqian.name
    return card
  end,
  -- before_use = function(self, player, use)
  --   local ids = Card:getIdList(use.card)
  --   if #ids == 1 and #player:getPile("$th_alice_renxing") == 1 then
  --     if player:getPileNameOfId(ids[1]) == "$th_alice_renxing" then
  --       use.extra_data = use.extra_data or {}
  --       use.extra_data.th_renxing_draw = true
  --     end
  --   end
  --   -- player.room:addTableMark(player, "_th_hunqian-turn", use.card.name)
  -- end,
  -- after_use = function(self, player, use)
  --   if (use.extra_data or Util.DummyTable).th_renxing_draw then
  --     player:drawCards(2, hunqian.name)
  --   end
  -- end,
  enabled_at_play = function(self, player)
    return #player:getPile("$th_alice_renxing") > 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getPile("$th_alice_renxing") > 0
  end,
  enabled_at_nullification = function(self, player)
    return #player:getPile("$th_alice_renxing") > 0
  end
}, { check_skill_limit = true })
Fk:loadTranslationTable{
  ["th_hunqian"] = "魂牵",
  [":th_hunqian"] = "每回合限一次，你可以将“人形”当普通锦囊牌使用。",
  ["#th_hunqian"] = "魂牵：将“人形”当【%arg】使用",

  ["#th_hunqian-draw"] = "并摸两张牌",
}

return hunqian